package com.erju.controller;

import cn.hutool.core.date.DateUtil;
import com.erju.pojo.SlLab;
import com.erju.pojo.SlLabAppointment;
import com.erju.service.SlLabService;
import com.erju.utils.Result;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author erju
 */
@RequestMapping("/lab")
@RestController
public class SlLabController {
    private static final Logger log = LoggerFactory.getLogger(SlLabController.class);

    @Resource
    SlLabService slLabService;

    /**
     * 查询所有实验室信息
     */
    @RequestMapping("/selectAll")
    public Result<?> selectAll() {
        return slLabService.selectAll();
    }

    /**
     * 模糊查询实验室
     */
    @RequestMapping("/selectLab/{pageNum}")
    public Result<?> selectLab(@RequestBody SlLab slLab,@PathVariable("pageNum") int pageNum) {
        log.info("查询页面参数" + pageNum);
        PageHelper.startPage(pageNum, 10);
        return slLabService.selectLab(slLab);
    }

    /**
     * 增加实验室
     */
    @RequestMapping("/addLab")
    public Result<?> addLab(@RequestBody SlLab slLab) {
        return slLabService.addLab(slLab);
    }

    /**
     * 实验室名称查询实验室
     *
     * @return com.erju.utils.Result<?>
     * @Author erju
     * @Date 16:37 2022/3/21
     **/
    @RequestMapping("/selectLabBySite")
    public Result<?> selectLabBySite() {
        return slLabService.selectLabBySite();
    }

    /***
     *删除实验室
     * @Author erju
     * @Date 14:40 2022/3/24
     * @Param [slLab]
     * @return com.erju.utils.Result<?>
     **/
    @RequestMapping("/deleteLab")
    public Result<?> deleteLab(@RequestBody SlLab slLab) {
        return slLabService.deleteLab(slLab);
    }

    /***
     *id查询实验室信息
     * @Author erju
     * @Date 14:28 2022/3/24
     * @Param [map]
     * @return com.erju.utils.Result<?>
     **/
    @RequestMapping("/selectLabById")
    public Result<?> selectLabById(@RequestBody Map<?, ?> map) {
        Integer id = (Integer) map.get("id");
        log.info(id.toString());
        return slLabService.selectLabById(id);
    }

    /***
     *更新实验室信息
     * @Author erju
     * @Date 14:49 2022/4/2
     * @Param [slLab]
     * @return com.erju.utils.Result<?>
     **/
    @RequestMapping("/updateLab")
    public Result<?> updateLab(@RequestBody SlLab slLab) {
        return slLabService.updateLab(slLab);
    }


}
